<template>
    <el-drawer v-model="showDrawer" :title="title" :size="size" :destroy-on-close="destroyOnClose" direction="rtl">
        <div class="formDrawer">
            <div class="body">
                <slot></slot>
            </div>
            <div class="actions">
                <el-button type="primary" @click="submit" :loading="loading">{{ confirmText }}</el-button>
                <el-button type="default" @click="close">取 消</el-button>
            </div>
        </div>
    </el-drawer>
</template>
<script setup>
import { ref } from "vue"
const showDrawer = ref(false)

const props = defineProps({
    title:String,
    size:{
        type:String,
        default:"30%"
    },
    destroyOnClose:{
        type:Boolean,
        default:false
    },
    confirmText:{
        type:String,
        default:"提交"
    }

})

const open = () => showDrawer.value = true

const close = () => showDrawer.value = false

const loading = ref(false)
const showLoading = ()=>loading.value = true
const hideLoading = ()=>loading.value = false
// 提交
const emit = defineEmits(["submit"])
const submit = ()=> emit("submit")

// 向父组件暴露以下方法
defineExpose({
    open,
    close,
    showLoading,
    hideLoading
})
</script>
<style>
.formDrawer {
    width: 100%;
    height: 100%;
    position: relative;
    @apply flex flex-col
}
.formDrawer .body{
    @apply overflow-y-auto;
}
.formDrawer .actions{
    height: 50px;
    @apply mt-auto flex items-center
}
</style>